//
//  YZSignAPI.m
//  VET
//
//  Created by Lam BG on 2018/6/29.
//  Copyright © 2018年 YZ. All rights reserved.
//

#import "YZSignAPI.h"

#import "YZUser.h"

#import "NSString+Security.h"

@implementation YZSignAPI

// 验证手机号码是否存在
+ (RACSignal*)apiCheckUserMobile:(NSString*)number {
    
    YZSignAPI *api = [YZSignAPI api];
    api.action = kAPIUserMobile;
    api.showLoadingStatus = NO;
    
    [api addParams:@{
                     @"userType" : @"mobile",
                     @"userCode" : number
                     }];
    
    return [api getRequest];
}

// 发送短信验证码
+ (RACSignal*)apiGetUserMessage:(NSString*)number {
    
    YZSignAPI *api = [YZSignAPI api];
    api.action = [NSString stringWithFormat:@"%@/%@", kAPIUserMessage, number];
    api.showLoadingStatus = YES;
    
    [api addParams:@{
                     @"mobile" : number
                     }];
    
    return [api getRequest];
}

// 注册
+ (RACSignal*)apiRegistUser:(NSString*)number password:(NSString*)password verCode:(NSString*)verCode uid:(NSString*)uid {
    
    YZSignAPI *api = [YZSignAPI api];
    api.action = kAPIUserConsumer;
    api.showLoadingStatus = YES;
    
    [api addParams:@{
                     @"mobile" : number,
                     @"password": [password base64],
                     @"uniqueId": uid,
                     @"userType": @"mobile",
                     @"verCode": verCode
                     }];
    
    return [api postRequest];
}

// 登录
+ (RACSignal*)apiLoginUserMobile:(NSString*)number andPassword:(NSString*)password
                     deviceToken:(NSString *)deviceToken {
    
    YZSignAPI *api = [YZSignAPI api];
    api.action = kAPIUserMobile;
    api.showLoadingStatus = YES;
    
    [api addParams:@{
                     @"password" : [password base64],
                     @"mobile" : number,
                     @"deviceToken":kText(deviceToken)
                     }];
    
    return [api postRequest];
}

// 微信登录
+ (RACSignal*)apiWeChatLogin:(NSString*)code {
    
    YZSignAPI *api = [YZSignAPI api];
    api.action = kAPIUserWeChatLogin;
    api.showLoadingStatus = YES;
    
    [api addParams:@{
                     @"code" : code
                     }];
    
    return [api postRequest];
}

+ (YZSignAPI*)inputUserInfoAPI {
    
    YZSignAPI *api = [YZSignAPI api];
    api.action = kAPIUserUserInfo;
    api.showLoadingStatus = YES;
    
    if ([YZUser sharedInstance].uid.length) {
        
        [api addParams:@{
                         @"id" : [YZUser sharedInstance].uid
                         }];
    }
    
    return api;
}

+ (RACSignal*)apiSignOut {
    
    YZSignAPI *api = [YZSignAPI api];
    api.action = kAPIUserUser;
    api.showLoadingStatus = YES;
    
    return [api deleteRequest];
}

@end


















